package unamur.iodass.ws.catalogclient;

import java.rmi.RemoteException;
import java.util.ArrayList;

import org.apache.axis2.AxisFault;

import unamur.iodass.communication.messages.Book;
import unamur.iodass.ws.catalogclient.CatalogServStub.GetCatalog;
import unamur.iodass.ws.catalogclient.CatalogServStub.GetCatalogResponse;


public class CatalogClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		CatalogServStub cstub;
		try {
			cstub = new CatalogServStub();
		

		GetCatalog catalog = new GetCatalog();
		
		GetCatalogResponse catalogResponse = cstub.getCatalog(catalog);
		System.out.println(catalogResponse);	
		
		if (catalogResponse.is_returnSpecified()) {
			/*
			String[] books;
			books = catalogResponse.get_return();
			String str = "";
			for (int i=0; i<books.length; i++) {
			str += books[i]+"\n";
			} 
		*/
			unamur.iodass.ws.catalogclient.CatalogServStub.Book[] books = catalogResponse.get_return();
			String str = "";
			for (int i=0; i<books.length; i++) {
				str += books[i].getIsbn() + "\t" + books[i].getTitle() + "\t" + books[i].getAuthor()+ "\t" + books[i].getLanguage() + "\n";
			}
			System.out.println("Catalog is " + str);
			//System.out.println("Catalog is " + str);
		} else {
			System.out.println("unable to retrieve catalog.");	
			//System.exit(-1);
		}
		
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println(e);	
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println(e);	
		}
	}

}
